part of markdown;

extension Aux on Directory {
  bool get isPaper => name.contains(".") && !name.startsWith(".");

  File get mdFile {
    for (final file in subFiles) {
      if (file.name == _Tx.md) return file;
    }
    throw Exception("在文件夹${name}中没有找到${_Tx.md}");
  }

  /// 如果不存在，创建一个
  Directory get photoFolder {
    for (final folder in subFolders) {
      if (folder.name == _Tx.photos) return folder;
    }
    return Directory("$path/${_Tx.photos}")..createSync();
  }

  File findPhoto(String name) {
    for (final file in photoFolder.subFiles) {
      if (file.isPhoto && file.name == name) return file;
    }
    throw Exception("在文件夹${path}中没有找到图片$name");
  }
}
